package cn.tedu.egmvc3.base.response;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

/**
 * 响应结果
 */
@Setter
@Getter
@NoArgsConstructor//无参构造
@AllArgsConstructor//全参构造
public class JsonResult {
    private Integer state;
    private String message;
    private Object data;
    /*
    无返回值的构造
     */
    public JsonResult(StatusCode statusCode){
        this.state = statusCode.getState();
        this.message = statusCode.getMessage();
    }
    /*
    有返回值的构造
     */
    public JsonResult(StatusCode statusCode,Object data){
        this.state = statusCode.getState();
        this.message = statusCode.getMessage();
        this.data = data;
    }
    /*
    针对成功的场景，封装两个静态方法
    1、成功无返回值
    2、成功有返回值
     */
    public static JsonResult ok(Object data) {
        return new JsonResult(StatusCode.OPERATION_SUCCESS, data);
    }
    public static JsonResult ok() {
        //return new JsonResult(StatusCode.OPERATION_SUCCESS);
        return ok(null);
    }
}
